package com.smart.campus.web.controller.school;

import java.util.Date;
import java.util.List;

import com.qiniu.storage.model.DefaultPutRet;
import com.smart.campus.framework.util.QiNiuFileOptUtil;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpRequest;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.*;
import com.smart.campus.common.annotation.Log;
import com.smart.campus.common.enums.BusinessType;
import com.smart.campus.school.domain.AppVersion;
import com.smart.campus.school.service.IAppVersionService;
import com.smart.campus.common.core.controller.BaseController;
import com.smart.campus.common.core.domain.AjaxResult;
import com.smart.campus.common.utils.poi.ExcelUtil;
import com.smart.campus.common.core.page.TableDataInfo;
import org.springframework.web.multipart.MultipartFile;

import javax.servlet.http.HttpServletRequest;

/**
 * app版本管理Controller
 * 
 * @author Zhihe.Li
 * @date 2021-06-23
 */
@Controller
@RequestMapping("/school/appVersion")
public class AppVersionController extends BaseController
{
    private String prefix = "school/appVersion";

    @Autowired
    private IAppVersionService appVersionService;

    @RequiresPermissions("school:appVersion:view")
    @GetMapping()
    public String appVersion()
    {
        return prefix + "/appVersion";
    }

    /**
     * 查询app版本管理列表
     */
    @RequiresPermissions("school:appVersion:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(AppVersion appVersion)
    {
        startPage();
        List<AppVersion> list = appVersionService.selectAppVersionList(appVersion);
        return getDataTable(list);
    }

    /**
     * 导出app版本管理列表
     */
    @RequiresPermissions("school:appVersion:export")
    @Log(title = "app版本管理", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(AppVersion appVersion)
    {
        List<AppVersion> list = appVersionService.selectAppVersionList(appVersion);
        ExcelUtil<AppVersion> util = new ExcelUtil<AppVersion>(AppVersion.class);
        return util.exportExcel(list, "appVersion");
    }

    /**
     * 新增app版本管理
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存app版本管理
     */
    @RequiresPermissions("school:appVersion:add")
    @Log(title = "app版本管理", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave( AppVersion appVersion)
    {

        return toAjax(appVersionService.insertAppVersion(appVersion));
    }

    /**
     * 修改app版本管理
     */
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") Long id, ModelMap mmap)
    {
        AppVersion appVersion = appVersionService.selectAppVersionById(id);
        mmap.put("appVersion", appVersion);
        return prefix + "/edit";
    }

    /**
     * 修改保存app版本管理
     */
    @RequiresPermissions("school:appVersion:edit")
    @Log(title = "app版本管理", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(AppVersion appVersion)
    {
        return toAjax(appVersionService.updateAppVersion(appVersion));


    }

    /**
     * 删除app版本管理
     */
    @RequiresPermissions("school:appVersion:remove")
    @Log(title = "app版本管理", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(appVersionService.deleteAppVersionByIds(ids));
    }
}
